package com.lichao.FinkDataProcess.rel;

import com.alibaba.fastjson.JSONObject;
import com.lichao.FinkDataProcess.compare.CompareNode;

import java.io.Serializable;

/**
 * @author: li chao
 * @Desc:
 * @create: 2024-11-15 21:10
 **/
public class AndNode extends RelNode implements Serializable {

    public AndNode() {
        init();
    }

    @Override
    public boolean apply(JSONObject json) throws Exception {
        boolean flag = true;
        for (Node node : getChildNodes()) {
            if (node instanceof CompareNode) {
                flag = ((CompareNode) node).compare(json);
                if (!flag) {
                    return false;
                }
            }

            if (node instanceof RelNode) {
                flag = ((RelNode) node).apply(json);
                if (!flag) {
                    return false;
                }
            }
        }
        return flag;
    }

}
